import {defHttp} from '/@/utils/http/axios';
import {useMessage} from "/@/hooks/web/useMessage";

const {createMessage} = useMessage();

enum Api {
  listPage = '/act/procinst/listPage',
  getProcInstance = '/act/procinst/getProcInstance',
  save = '/act/procinst/add',
  updateState = '/act/procinst/updateState',
  convertToModel = '/act/procinst/convertToModel',
  deleteOne = '/act/procinst/delete',
  endOne = '/act/procinst/endProcess',
  getFlowchart = '/act/procinst/resourceImage',
}

/**
 * 列表接口
 * @param params
 */
export const listPage = (params) => defHttp.get({url: Api.listPage, params});

/**
 * 获取流程实例
 * @param params
 */
export const getProcessInstance = (params: any) => defHttp.get({url: Api.getProcInstance, params});

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({url: Api.deleteOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 结束单个
 * @param params
 * @param handleSuccess
 */
export const endOne = (params, handleSuccess) => {
  return defHttp.get({url: Api.endOne, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 激活和挂起
 * @param params
 * @param isUpdate
 */
export const updateState = (params, handleSuccess) => {
  return defHttp.get({url: Api.updateState, params}).then(() => {
    handleSuccess();
  });
}

export const convertToModel = (params) => {
  return defHttp.get({url: Api.convertToModel, params}).then(res => {
    console.log(res)
    createMessage.success('成功转换为模型，模型id=' + res.id);
  });
}

export const getFlowchart = (params, handleSuccess) => {
  return defHttp.get({url: Api.getFlowchart, params}).then(res => {
    handleSuccess(res);
  });
}
